home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
-
- Program name: Colour naming scheme.
-
- Author: Gareth Williams
-
- Description: Demonstrates the Colour Naming Scheme of the PHIGS Toolkit.
- Users may type in colour names and the colour will be displayed on the
- screen.
-
- Modification history : (Version), (Date), (Name), (Description).
-
- 1.0, 18th February 1991, G. Williams, First Version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- #define WS1 1
- #define TABLE 1
-
- /* Operating system dependent code, UNIX/VMS pathnames */
- /* UNIX pathname */
- #define OPENWSNAME "../scripts/openws.scr"
-
- /* for gamma correction */
- #define GAMMA 1.0
- #ifdef SUN
- #undef GAMMA
- #define GAMMA 1.94
- #endif
- #ifdef PEXSI
- #undef GAMMA
- #define GAMMA 1.94
- #endif
- #ifdef HP
- #undef GAMMA
- #define GAMMA 2.56
- #endif
-
- static Pfloat devx, devy, devz;
-
- /*--------------------------------------------------------------------------*/
-
- static void outputcolourvalues(C(Pint) inum, C(char *) colourname,
- C(Prgb *) rgb)
- PreANSI(Pint inum)
- PreANSI(char *colourname)
- PreANSI(Prgb *rgb)
- /* Output colour model values of colourname in RGB, HSV and HSL
- ** coordinates.
- */
- {
- Phls hsl;
- Phsv hsv;
-
- printf("%d) RGB value of %s is %f %f %f\n", inum, colourname, rgb->red,
- rgb->green, rgb->blue);
- ptk_rgbtohsv(rgb, &hsv);
- printf("%d) HSV value of %s is %f %f %f\n", inum, colourname, hsv.hue,
- hsv.satur, hsv.value);
- ptk_rgbtohsl(rgb, &hsl);
- printf("%d) HSL value of %s is %f %f %f\n\n", inum, colourname, hsl.hue,
- hsl.satur, hsl.lightness);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void options(C(void))
- /* enable input of colour names using PHIGS string device */
- {
- char colourname[50];
- Pint err, lencolourname;
- ptkboolean cnsquit;
- Plimit echoarea;
- Pcolr_rep rgb;
-
- cnsquit = FALSE;
- echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
- do
- {
- /* input a colour name and display the colour */
- ptk_readstring(WS1, "white", "Input colourname (white) >", &echoarea,
- 50, colourname, &lencolourname);
- if (strncmp(colourname, "quit", lencolourname) == 0)
- {
- cnsquit = TRUE;
- }
- else
- {
- /* convert colourname to RGB colour model */
- ptk_cnstorgb(colourname, &rgb.rgb);
-
- /* gamma correct */
- rgb.rgb.red = pow(rgb.rgb.red, 1.0/GAMMA);
- rgb.rgb.green = pow(rgb.rgb.green, 1.0/GAMMA);
- rgb.rgb.blue = pow(rgb.rgb.blue, 1.0/GAMMA);
-
- /* set entry in colour table */
- pset_colr_rep(WS1, 1, &rgb);
- pempty_struct(TABLE);
- /* display entry in colour table */
- ptk_drawcolourtable(TABLE, 1, 1);
- outputcolourvalues(1, colourname, &rgb.rgb);
- }
- pupd_ws(WS1, PFLAG_PERFORM);
- } while (cnsquit == FALSE);
- }
-
- /*--------------------------------------------------------------------------*/
-
- main()
- {
- FILE *fileptr;
- Pint i, numcolours;
- char colourname[64], dummystr[255];
- Pint dummylen;
- Plimit echoarea;
- Pint wst;
-
- /* open PHIGS */
-
- printf("Demonstrating the Colour Naming Scheme of the PHIGS Toolkit...\n");
-
- /* Implementation dependent code, open PHIGS and workstation */
- #ifdef SUN
- printf("Opening SunPHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
-
- /* create the workstation type (tool)
-
- wst = phigs_ws_type_create( phigs_ws_type_x_tool,
- PHIGS_COLOUR_MODE, PHIGS_INDEX_COLOUR,
- PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
- 0);
- if ( !wst )
- {
- pclose_phigs();
- exit(1);
- }
-
- popen_ws(WS1, (void *)NULL, wst);
- {
- Pws_st ws_state;
-
- pinq_ws_st(&ws_state);
- if (ws_state != PWS_ST_WSOP)
- exit(3);
- }
- */
- #endif
- #ifdef PEXSI
- printf("Opening PEX-SI PHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef HP
- printf("Opening HP PHIGS...\n");
- popen_phigs(stderr, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
-
- ptk_inqmaxdevicecoords(WS1, &devx, &devy);
- devz = 0.0;
-
- /* set up hashstrings colour table */
- ptk_inithashtables();
- ptk_createhashtable("colourindex", 1, 256);
-
- pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
-
- ptk_drawcolourtable(TABLE, 0, 0);
- ppost_struct(WS1, TABLE, 0.0);
-
- pupd_ws(WS1, PFLAG_PERFORM);
-
- options();
-
- pclose_ws(WS1);
- printf("Closing PHIGS...\n");
- pclose_phigs();
- exit(0);
- }
-
- /*--------------------------------------------------------------------------*/
-
- /* end of cnstest.c */
-